<include file="Common/header" />
<title>物品录入</title>
<script type="text/javascript" src="__PUBLIC__/h-ui/lib/jquery/1.9.1/jquery.form.js"></script>
<script>
	/**
	 * 上传图片
	 **/
	function uploadImages(){
		var load = layer.load(2);
		$("#uploadform").ajaxSubmit({
			type:'post',
			url:'../index/upload.html',
			success:function(data){
				layer.close(load);
				var data = JSON.parse(data);
				if(data.errCode/1 > 0){
					layer.msg('上传成功', {icon:1, time: 2000});
					$("#images").val(data.errMsg);
					$("#imgshow").show();
					$("#imgshow img").attr('src', "__PUBLIC__/upload/"+ data.errMsg);
				}else{
					layer.msg(data.errMsg, {icon:2, time: 2000});
				}
			},
			error:function(XmlHttpRequest,textStatus,errorThrown){
				
			}
		});
	}
</script>
</head>
<body>
<div class="pd-20">
	<div class="panel panel-primary">
		<div class="panel-header">基本信息</div> 
		<table class="table table-border table-bordered table-striped">
            <tr>
               	<td style="background-color: #f9f9f9;text-align: right">物品编号：</td>
                <td style="background-color: white">
					<input type="hidden" name="accessid" id="accessid" value="{$info['access_id']}" />
					<input type="text" name="access_no" id="access_no" class="input-text radius" value="{$info['access_no']}" />
				</td>
				<td style="background-color: #f9f9f9;text-align: right">物品名称：</td>
                <td style="background-color: white">
					<input type="text" name="title" id="title" class="input-text radius" value="{$info['title']}" />
				</td>
				<td style="background-color: #f9f9f9;text-align: right">物品状态：</td>
                <td style="background-color: white">
					<span class="select-box radius">
						<select class="select" size="1" name="visible" id="visible">
							<option value="1" {$info['visible'] == 1 ? 'selected' : ''}>正常</option>
							<option value="0" {$info['visible'] == 0 ? 'selected' : ''}>禁用</option>
						</select>
					</span>
				</td>
            </tr>
			<tr>
				<td style="background-color: #f9f9f9;text-align: right">成本价格：</td>
                <td style="background-color: white;">
					<input type="text" name="costprice" id="costprice" class="input-text radius" value="{$info['costprice']}" />
                </td>
				<td style="background-color: #f9f9f9;text-align: right">出租价格：</td>
                <td style="background-color: white;">
					<input type="text" name="price" id="price" class="input-text radius" value="{$info['price']}" />
                </td>
				<td style="background-color: #f9f9f9;text-align: right">减配价格：</td>
                <td style="background-color: white;">
					<input type="text" name="subprice" id="subprice" class="input-text radius" value="{$info['subprice']}" />
                </td>
			</tr>
			<tr>
				<td style="background-color: #f9f9f9;text-align: right">出租数量：</td>
                <td style="background-color: white;">
					<input type="text" name="count" id="count" class="input-text radius" value="{$info['count']}" />
                </td>
				<td style="background-color: #f9f9f9;text-align: right">物品单位：</td>
                <td style="background-color: white;">
                	<input type="text" name="unit" id="unit" class="input-text radius" value="{$info['unit']}" />
                </td>
				<td style="background-color: #f9f9f9;text-align: right"></td>
                <td style="background-color: white;"></td>
			</tr>
			<tr>
				<td class="text-r">物品图标：</td>
				<td colspan="5">
					<form action="" method="post" class="form form-horizontal" id="uploadform" enctype="multipart/form-data">
						<span class="btn-upload"> 
							<a href="javascript:void();" class="btn btn-primary radius uploadBtn">
								<i class="Hui-iconfont"></i> 浏览文件
							</a>
							<input type="file" multiple="" name="file[]" class="input-file" onchange="uploadImages();">
						</span>
					</form>
					<input type="hidden" name="icon" id="icon" value="{$info['icon']}" />
					<div id="imgshow" style="display: <?php echo empty($info['icon']) ? 'none' : 'block'; ?>;">
						<hr />
						<img src="__PUBLIC__/upload/{$info['icon']}" style="width: 100px; height: 100px;"/>
					</div>
				</td>
			</tr>
			
		</table>
	</div>

	<div class="mt-5 mb-5 text-c">
		<button type="button" class="btn btn-success radius submitBtn" id="admin-role-save" name="admin-role-save">
			<i class="icon-ok"></i> 确  定
		</button>
	</div>
</div>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/ueditor.all.min.js"> </script>
<script>
	function uploadImages(){
		var load = layer.load(2);
		$("#uploadform").ajaxSubmit({
			type:'post',
			url:'../index/upload.html',
			success:function(data){
				layer.close(load);
				var data = JSON.parse(data);
				if(data.errCode/1 > 0){
					layer.msg('上传成功', {icon:1, time: 2000});
					$("#icon").val(data.errMsg);
					$("#imgshow").show();
					$("#imgshow img").attr('src', "__PUBLIC__/upload/"+ data.errMsg);
				}else{
					layer.msg(data.errMsg, {icon:2, time: 2000});
				}
			},
			error:function(XmlHttpRequest,textStatus,errorThrown){
				
			}
		});
	}
	
	function isNumber(s){
	    var regu = "^[0-9]+\.?[0-9]*$";
	    var re = new RegExp(regu);
	    if(re.test(s)){
	        return true;
	    }else{
	        return false;
	    }
	}
	
	$(document).ready(function(){
		/**
		 * 提交数据
		 **/
		$(".submitBtn").on('click', function(){
			var data = {};
			var accessno = $("#access_no").val() || "";
			if(accessno.length <= 0){
				layer.msg("请输入物品编号", {icon: 5, time: 2000});
				return false;
			}else{
				data.access_no = accessno;
			}

			if($("#title").val() == ""){
				layer.msg("请输入物品名称", {icon: 2, time:2000});
				return false;
			}else{
				data.title = $("#title").val();
			}

			var costprice = $("#costprice").val();
			if(costprice.length <= 0 || !isNumber(costprice)){
				layer.msg('请正确输入成本价格', {icon: 5, time: 2000});
				return false;
			}else{
				data.costprice = costprice;
			}
			
			var price = $("#price").val();
			if(price.length <= 0 || !isNumber(costprice)){
				layer.msg('请正确输入出租价格', {icon: 5, time: 2000});
				return false;
			}else{
				data.price = price;
			}
			
			var subprice = $("#subprice").val();
			if(subprice.length <= 0 || !isNumber(costprice)){
				layer.msg('请正确输入减配价格', {icon: 5, time: 2000});
				return false;
			}else{
				data.subprice = subprice;
			}
			
			var unit = $("#unit").val();
			if(unit.length <= 0){
				layer.msg('请输入物品单位', {icon: 5, time: 2000});
				return false;
			}else{
				data.unit = unit;
			}

			var images = $("#icon").val();
			if(images.length <= 0){
				layer.msg('请上传封面图片', {icon: 5, time: 2000});
				return false;
			}else{
				data.icon = images;
			}
			data.visible = $("#visible").val();
			data.count = $("#count").val() || 0;
			data.accessid = $("#accessid").val() || 0;
			var load = layer.load(2);
			$.post('add.html', data, function(row){
				layer.close(load);
				if(row == 1){
					layer.msg('编辑成功', {icon: 1, time: 2000}, function(){
						window.parent.location.reload(); //刷新
						var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    	parent.layer.close(index);
					});
				}else{
					layer.msg('编辑失败', {icon: 2, time: 2000});
				}
			});
		});
	});
</script>
</body>
</html>